﻿using System;
using System.Collections.Generic;
using Wei8808Cms.BLL;
using Wei8808Cms.Model;

namespace Wei8808Cms.WebSite
{
    public partial class Product : System.Web.UI.Page
    {
        private readonly ProductBLL _productBll = new ProductBLL();

        protected List<ProductInfo> ProductList = new List<ProductInfo>();

        public string DivNav = string.Empty;

        public string PDetal = string.Empty;

        protected int Id;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!int.TryParse(Request.Params["id"] as string, out this.Id))
            {
                InitializationData();
            }
            else
            {
                ProductList = _productBll.GetProductList();
                DivNav += "<ul class=\"filter option-set\" data-filter-group=\"categories\">";
                int idx = 1;
                foreach (var i in ProductList)
                {
                    if (Id == i.PId)
                    {
                        PDetal += "<div class=\"full_column element " + i.PId + "\">";
                        PDetal += " <div class=\"portfolio-box\"><p><strong>" + i.ProductName + "—" + i.ProductTitle + "</strong></p>" + i.ProductContent + "</div></div>";
                        DivNav += "<li><a class=\"selected\" data-filter-value=\"." + i.PId + "\" >" + i.ProductName + "</a></li>";
                    }
                    else
                    {
                        PDetal += "<div class=\"full_column element " + i.PId + "\">";
                        PDetal += " <div class=\"portfolio-box\"><p><strong>" + i.ProductName + "—" + i.ProductTitle + "</strong></p>" + i.ProductContent + "</div></div>";
                        DivNav += "<li><a data-filter-value=\"." + i.PId + "\" >" + i.ProductName + "</a></li>";
                    }
                    if (idx % 8 == 0)
                    {
                        DivNav += "</ul>";
                        DivNav += "<ul class=\"filter option-set\" data-filter-group=\"categories\">";
                    }
                    idx++;
                }
                DivNav += "</ul>";
            }
        }

        private void InitializationData()
        {
            ProductList = _productBll.GetProductList();
            DivNav += "<ul class=\"filter option-set\" data-filter-group=\"categories\">";
            int idx = 1;
            foreach (var i in ProductList)
            {
                PDetal += "<div class=\"full_column element " + i.PId + "\">";
                PDetal += " <div class=\"portfolio-box\"><p><strong>" + i.ProductName + "—" + i.ProductTitle + "</strong></p>" + i.ProductContent + "</div></div>";
                DivNav += "<li><a data-filter-value=\"." + i.PId + "\" >" + i.ProductName + "</a></li>";
                if (idx % 8 == 0)
                {
                    DivNav += "</ul>";
                    DivNav += "<ul class=\"filter option-set\" data-filter-group=\"categories\">";
                }
                idx++;
            }
            DivNav += "</ul>";





        }
    }
}